package org.DateFile;

import org.junit.Test;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.FileReader;

public class GatherTest {

    @Test
    public void test01() throws Exception {
        // 使用 try-with-resources 自动关闭流
        try (BufferedReader br = new BufferedReader(new FileReader("src/main/resources/data-file-simple"))) {
            System.out.println(br);
            // 读取一行数据
            String line = br.readLine();
            System.out.println("read: " + line);
        } // br 会在此处自动关闭，无需手动调用 close()
    }

    @Test
    public void test02() {
        String s1 = "100|101|2|16|1|3|5d806ff802|1|1516323615936";
//注意：| 是特殊字符，需要去除其特殊含义：[|] 或 \\|
        String[] split = s1.split("[|]");
        System.out.println("length: " + split.length);
        System.out.println(Arrays.toString(split));
    }

    @Test
    public void test03() {
//温湿度数据解析
        String s1 = "5d806ff802";
        String substring = s1.substring(0, 4);
        System.out.println(substring);
    }

    @Test
    public void test4() {
//将16进制的字符串 转换为 int值
        int i = Integer.parseInt("5d80", 16);
        System.out.println(i);
    }
}


